<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../libs/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../libs/app.css" />
		<link href="../../css/main.css" rel="stylesheet" />
		<link href="../../css/select-work.css" rel="stylesheet" />
	</head>

	<body>
		<div class="head">
			<img src="../../images/all-left.png" alt="" class="mui-action-back">
			<p>选择业务</p>
		</div>
		<div class="context">
			<p>可多选</p>
			<div class="bank" id="bank">
				<!--<div>
					<div>
						<span poin="card-native"></span>
					</div>
					<p>信用卡</p>
				</div>
				<div>
					<div>
						<span poin="xyd"></span>
					</div>
					<p>信用贷</p>
				</div>
				<div>
					<div>
						<span poin="fcdy"></span>
					</div>
					<p>房产抵押</p>
				</div>
				<div>
					<div>
						<span poin="2y"></span>
					</div>
					<p>二押</p>
				</div>
				<div>
					<div>
						<span poin="qcdy"></span>
					</div>
					<p>汽车贷</p>
				</div>
				<div>
					<div>
						<span poin="xed"></span>
					</div>
					<p>小额贷</p>
				</div>-->
			</div>
			<div class="button">
				<button id="fill">提交</button>
			</div>
		</div>
		<script src="../../libs/mui.min.js"></script>
		<script src="../../js/jquery-3.1.1.min.js"></script>
		<script src="../../js/url.js"></script>
		<script type="text/javascript">
			if(localStorage.fillin_type == '贷款中介') {
				localStorage.bank = '';
			}
			//获取该用户的没有的业务类型
			$.ajax({
				type: "get",
				url: ur + "rest/loanPartnerController/loanPartnerApply",
				async: true,
				headers: {
					'X-Token': localStorage.token
				},
				dataType: 'json',
				success: function(data) {
					if(data.meta.code === 'S002') {
						var list = data.data;
						if(list.length == 0) {
							$('.context').remove();
							mui.toast('您已无可新增的业务！');
						} else {
							for(var i = 0; i < list.length; i++) {
								var item = '<div class="item" ><div><span poin=' +
									list[i].code + '></span></div><p>' +
									list[i].name + '</p></div>';
								$('#bank').append(item);
							}
						}
					} else {
						mui.toast(data.meta.message);
					}
				}
			})

			//选择样式
			$('#bank').on('tap', '.item', function() {
				if($(this).find('span').attr('class') == 'active') {
					$(this).find('span').removeClass('active');
				} else {
					$(this).find('span').attr('class', 'active');
				}
			})
			$(function() {
				$('#fill').on('tap', function() {
					var arr = [];
					$('#bank span').each(function() {
						if($(this).attr('class') == 'active') {
							arr.push($(this).attr('poin'));
						}
					})
					localStorage.loans = arr.join();

					if(localStorage.loans == '') {
						mui.toast('请选择类型');
					} else {
						$.ajax({
							type: "post",
							url: ur + "rest/loanPartnerController/loanPartnerRequest",
							async: true,
							headers: {
								'X-Token': localStorage.token
							},
							dataType: 'json',
							data: {
								code: localStorage.loans,
								level: $('.active').parent().index(),
							},
							success: function(data) {
								if(data.meta.code === 'S002') {
									mui.init({
										beforeback: function() {
											//获得列表界面的webview
//											var list = plus.webview.getWebviewById('agent');
											//触发列表界面的自定义事件（refresh）,从而进行数据刷新
//											mui.fire(list, 'agents');
											//返回true，继续页面关闭逻辑
											return true;
										}
									})
									mui.back();
								} else {
									mui.toast(data.meta.message);
								}
							}
						});
					}
				})
			})
		</script>
	</body>

</html>